var pageSize = 5;
var pageNum = 1;
var totalNum = 1;
var url = "";

function searchData() {
    $('#bootstrap-table').bootstrapTable('removeAll');//清空数据
    pageNum = 1;//重置页面为1
    totalNum = 1;
    getDataList();
}

// 滚动事件
window.onscroll = function () {
    // 可滚动高度
    let scrollHeight = () =>
        document.body.scrollHeight || document.documentElement.scrollHeight;
    // 可视窗口高度
    let keshiHeight = () =>
        window.innerHeight ||
        document.documentElement.clientHeight ||
        document.body.clientHeight;

    // 注：小米浏览器对于scrollTop的值会有小数，需要做取整操作
    // 向上滚动的高度，各大浏览器的计算法则不一样，得到的值可能有小数
    let scrollTopHeight = () =>
        Math.ceil(document.body.scrollTop || document.documentElement.scrollTop);

    // console.log("监听页面滚动事件")
    // console.log(height)
    // console.log(scrollHeight(),keshiHeight(),scrollTopHeight())
    if (scrollHeight() - 50 <= keshiHeight() + scrollTopHeight()) {
        // load data
        console.log("滚动到达底部")
        if (totalNum > 0) {
            // 调用接口分页
            pageNum = pageNum + 1;
            // 获取新闻列表
            console.log("调用接口", pageNum, pageSize)
            // 获取路线列表
            getDataList();
        }
    }
}

function getDataList(urls) {
    if ($.common.isNotEmpty(urls)) {
        url = urls;
    }
    var currentId = $('form').attr('id');
    var search = {};
    $.each($("#" + currentId).serializeArray(), function (i, field) {
        search[field.name] = field.value;
    });
    search.pageSize = pageSize;
    search.pageNum = pageNum;
    $.ajax({
        type: "POST",
        url: url,
        data: search,
        async: false,
        success: function (data) {
            if (data.total <= pageSize * pageNum) {
                totalNum = 0;
            }
            $("#bootstrap-table").bootstrapTable('append', data.rows);
        }
    })
}

//搜索框隐藏，显示
function down() {
    $(".up").show();
    $(".down").hide();
}

function up() {
    $(".down").show();
    $(".up").hide();
}